package com.cskaoyan.util;
import com.cskaoyan.bean.MarketUser;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.springframework.util.ObjectUtils;

/**
 * @author LC_RSH
 * @date 2022/6/30 19:21
 */
public class CurrentUserUtils {
    public static MarketUser getUser() {
        MarketUser user = new MarketUser();
        user.setId(0);
        Subject subject = SecurityUtils.getSubject();
        PrincipalCollection principals = subject.getPrincipals();
        if (!ObjectUtils.isEmpty(principals)){
            user = (MarketUser) principals.getPrimaryPrincipal();
        }
        return user;
    }
}

/**
 * 得到当前用户信息
 *
 * @author 86157
 * @since 2022/06/30 19:21
 */